package service.impl;

import service.SysUserService;
import mapper.SysUserMapper;
import org.springframework.stereotype.Service;
import pojo.SysUser;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class SysUserServiceImpl implements SysUserService {
    @Resource
    SysUserMapper sysUserMapper;

    @Override
    public SysUser login(String account, String password) {
        SysUser sysUser=sysUserMapper.selectAccount(account);
        if(sysUser!=null){
            if(sysUser.getPassword().equals(password)){
                return sysUser;
            }
        }
        return null;
    }

    @Override
    public List<SysUser> selectList(String realName, Integer roleId, Integer pageNo, Integer pageSize) {
        int pageBegin=(pageNo-1)*pageSize;
        return sysUserMapper.selectList(realName,roleId,pageBegin,pageSize);
    }

    @Override
    public int selectCount(String realName, Integer roleId) {
        return sysUserMapper.selectCount(realName,roleId);
    }

    @Override
    public int insert(SysUser sysUser) {
        //设置创建时间为当前时间
        sysUser.setCreatedTime(new Date());
        return sysUserMapper.insert(sysUser);
    }

    @Override
    public SysUser selectById(Integer id) {
        return sysUserMapper.selectById(id);
    }

    @Override
    public int update(SysUser sysUser) {
        //设置修改时间为当前时间
        sysUser.setUpdatedTime(new Date());
        return sysUserMapper.update(sysUser);
    }

    @Override
    public SysUser selectAccount(String account) {
        return sysUserMapper.selectAccount(account);
    }

    @Override
    public int delete(int id) {
        return sysUserMapper.delete(id);
    }

}
